
interface CardState {
  cards: { id: number; value: number }[];
}

const initialState: CardState = {
  cards: [
    { id: 1, value: 1 },
    { id: 2, value: 2 },
    { id: 3, value: 3 },
    { id: 4, value: 4 },
    { id: 5, value: 5 },
  ],
};

const cardsModule = {
  namespaced: true,
  state: initialState,
  mutations: {
    SHUFFLE_CARDS(state) {
      const shuffled = [...state.cards].sort(() => Math.random() - 0.5);
      state.cards = shuffled;
    },
    UPDATE_CARD_VALUE(state, { id, value }: { id: number; value: number }) {
      const card = state.cards.find((c) => c.id === id);
      if (card) {
        card.value = value;
      }
    },
  },
  actions: {
    shuffleCards({ commit }) {
      commit('SHUFFLE_CARDS');
    },
    updateCardValue({ commit }, payload: { id: number; value: number }) {
      commit('UPDATE_CARD_VALUE', payload);
    },
  },
  getters: {
    cards: (state) => state.cards,
  },
};

export default cardsModule;